package tmhprediction.test;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.HashMap;

import tmhprediction.classification.TMHClassifier;
import tmhprediction.eval.TMHResidueEvaluator;
import tmhprediction.main.TMHResultMap;

public class TimeCheckEvaluators {

	/**
	 * @param args
	 * @throws Exception 
	 */
	
	public static void main(String[] args) throws Exception
	{
		String modelf = args[0];
		String outp = args[1];
		String testf = args[2];
		
//		useWekaInternal(modelf,outp, testf);
		
		useHunni(modelf, outp, testf);

		//'Hunni' wins
	}

	public static void useWekaInternal(String modelf, String outp, String testf) throws Exception
	{
		double timeBefore = System.currentTimeMillis();
		
		TMHClassifier classifier = new TMHClassifier(modelf, testf);
		
		classifier.createOutputFromEvaluation(outp+"/wekainternal");
		
		double timeAfter = System.currentTimeMillis();
		double diff = timeAfter-timeBefore;
		diff = (diff / 1000) / 60;
		System.out.println("WEKA internal. Ran for (m): "+diff);
	}
	
	public static void useHunni(String modelf, String outp, String testf) throws Exception
	{
		double timeBefore = System.currentTimeMillis();
		
		TMHClassifier classifier = new TMHClassifier(modelf, testf);
	
		System.out.println("Classifier built");
		
		TMHResultMap map = classifier.createResultMap();
		
		double timeAfterClassify = System.currentTimeMillis();
		double diff = timeAfterClassify-timeBefore;
		diff = (diff / 1000) / 60;	
		System.out.println("Hunni, up to classify, ran for (m): "+diff);
		
	    TMHResidueEvaluator.calcPerResidueScores(map, outp+"/hunni2");
		
		File f = new File(outp+"/hunni");
		BufferedWriter writer = new BufferedWriter(new FileWriter(f));
		
	
		TMHResultMap result = TMHResidueEvaluator.evaluateProteins(map);
	    for (String key : result.keySet()) {
		double[] resultValues = result.get(key);
		writer.append(key + ": " + resultValues[0] + "; "
			+ resultValues[1] + "; " + resultValues[2]);
		writer.newLine();
	    }
	    writer.close();
	    
		double timeAfter = System.currentTimeMillis();
		double diff2 = timeAfter-timeAfterClassify;
		diff2 = (diff2 / 1000.0) / 60.0;	
		System.out.println("Hunni. After Classify, ran for (m): "+diff2);
	}
}
